<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;

class ComponentCategory extends Model
{

    //define table name
    protected $table = 'component_categories';

    public function components():BelongsToMany
    {
        return $this->belongsToMany(Component::class, 'component_component_category');
    }

    public function parent()
    {
        return $this->belongsTo(ComponentCategory::class, 'parent_id');
    }

    public function children()
    {
        return $this->hasMany(ComponentCategory::class, 'parent_id');
    }
}
